# Maintainer: Oleg Tolmatcev <oleg.tolmatcev@gmail.com>

_realname=qpdf
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=8.0.0 
pkgrel=1
pkgdesc="QPDF is a program that does structural, content-preserving transformations on PDF files (mingw-w64)"
arch=('any')
url="http://qpdf.sourceforge.net/"
license=("custom:Artistic-2.0")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libjpeg"
         "${MINGW_PACKAGE_PREFIX}-pcre"
         "${MINGW_PACKAGE_PREFIX}-zlib")
source=("http://sourceforge.net/projects/${_realname}/files/${_realname}/${pkgver}/${_realname}-${pkgver}.tar.gz"
        "0001-fix-printf-on-mingw-w64.patch"
        "0002-enable-advapi32-mingw.patch"
        "0003-install-rule.patch")
md5sums=('a82d77f248de768478f3a8da2eaa693e'
         'f5d252e8aa12c68acf294306137d2375'
         '6cf1076ecbba51a8eb96dc7071b8bb77'
         'f39aae4a6055d700ed4cecd200ba5813')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-fix-printf-on-mingw-w64.patch"
  patch -p1 -i "${srcdir}/0002-enable-advapi32-mingw.patch"
  patch -p1 -i "${srcdir}/0003-install-rule.patch"

  ./autogen.sh
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  cp -rf ${_realname}-${pkgver} build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  ./configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST} \
      --disable-test-compare-images \
      --enable-external-libs \
      --with-windows-wordsize=${MINGW_PREFIX: -2} \
      --with-buildrules=mingw
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
